<?php
/**
 * Created by PhpStorm.
 * User: Shroom Ari
 * Date: 12/22/14
 * Time: 10:41 AM
 */
class Invoice extends MY_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->layout->setLayout('backend/index');
    }
    public function listInvoice($page=1){
        $data['seo']['title']='Invoice';
        $total_invoice= $this->minvoice->countAll();
        $perpage = 5;
        $config['base_url'] = "/petshop/backend/invoice/listInvoice/"; // xác định trang phân trang
        $config['total_rows'] = $total_invoice; // xác định tổng số record
        $config['per_page'] = $perpage; // xác định số record ở mỗi trang
        $config['num_links'] = 10;
        $config['cur_page'] =$page;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        $data['_config']= $config;
        $data['_page']=$page;
        $offset = ($page-1) * $perpage;
        $data['invoice']= $this->minvoice->getInvoice($perpage,$offset);
        $this->layout->view('backend/layout/invoice', $data);
    }
    public function detail($id){
        $data['seo']['title']='Invoice detail';
        $data['invoice']= $this->minvoice->getInvoiceById($id);
        $data['invoiceById']= $this->minvoicedetail->getInvoiceDetailById($id);
        if (isset($_POST['submit']) and $_POST['submit'] == 'delivery'){
            $data_invoice = array('status'=> '1');
            $this->minvoice->updateInvoice($data_invoice, $id);
            redirect('backend/invoice/detail/'.$id);
        }
        elseif (isset($_POST['submit']) and $_POST['submit'] == 'cancel'){
            $data_invoice = array('status'=> '2');
            $this->minvoice->updateInvoice($data_invoice, $id);
            redirect('backend/invoice/detail/'.$id);
        }
        $this->layout->view('backend/layout/invoice_detail', $data);
    }
    public function invoiceR($id){
        $data['seo']['title']='Invoice Customer';
        $data['invoice'] = $this->minvoice->getInvoiceById($id);
        $this->load->view('backend/layout/invoice_report', $data);
    }
}